package com.example.myproject.controller;

import com.example.myproject.entity.UserEntity;
import com.example.myproject.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * controller 负责页面访问控制
 * 前端控制器类
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
    @RequestMapping("/person")
    public String index() {
        return "Hello Spring Boot 2.0!";
    }

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/getUsers")
    public List<UserEntity> getUsers() {
        List<UserEntity> users=userMapper.getAll();
        return users;
    }

    @RequestMapping("/getUser")
    public UserEntity getUser(String cardNo) {
        UserEntity user=userMapper.getOne(cardNo);
        return user;
    }

    @RequestMapping("/add")
    public void save(UserEntity user) {
        userMapper.insert(user);
    }

    @RequestMapping(value="update")
    public void update(UserEntity user) {
        userMapper.update(user);
    }

    @RequestMapping(value="/delete/{cardNo}")
    public void delete(@PathVariable("cardNo") String cardNo) {
        userMapper.delete(cardNo);
    }

}